﻿package com.sh.game.loader
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import morn.core.handlers.*;
    import morn.core.managers.*;

    public class MovieResLoader extends Object
    {
        private var _loader:Loader;
        private var _completeFunc:Function;
        private var _curloader:MassLoaderManager;
        private var _url:String;
        private var _args:Array;
        private var _disposed:Boolean = false;

        public function MovieResLoader()
        {
            return;
        }// end function

        public function load(param1:String, param2:int, param3:Function, param4:int = 3, param5:Array = null, param6:Boolean = false) : void
        {
            this._disposed = false;
            this._args = param5;
            this._completeFunc = param3;
            if (param4 == 3)
            {
                this._curloader = App.leisureMloader;
            }
            else
            {
                this._curloader = App.mloader3;
            }
            this._url = param1;
            this._curloader.loadBYTE(param1, param2, new Handler(this.completeFunc), null, null, param6);
            return;
        }// end function

        private function completeFunc(param1) : void
        {
            if (param1 != null)
            {
                this._loader = new Loader();
                this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.swfComplete);
                this._loader.loadBytes(param1 as ByteArray);
            }
            else
            {
                if (this._completeFunc != null)
                {
                    this._completeFunc.apply(null, this._args ? (this._args.concat(null)) : ([null]));
                }
                this._completeFunc = null;
                this.dispose();
            }
            return;
        }// end function

        protected function swfComplete(event:Event) : void
        {
            var _loc_2:* = event.currentTarget as LoaderInfo;
            if (this._disposed)
            {
                _loc_2.loader.unloadAndStop(false);
                return;
            }
            _loc_2.removeEventListener(Event.COMPLETE, this.swfComplete);
            if (this._completeFunc != null)
            {
                this._completeFunc.apply(null, this._args ? (this._args.concat(_loc_2.applicationDomain)) : ([_loc_2.applicationDomain]));
            }
            this._completeFunc = null;
            this.dispose();
            return;
        }// end function

        public function dispose() : void
        {
            if (!this._disposed)
            {
                try
                {
                    if (this._loader)
                    {
                        this._loader.unloadAndStop(false);
                        this._loader.unload();
                        this._loader = null;
                    }
                }
                catch (error:Error)
                {
                }
                if (this._loader)
                {
                    this._loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, this.swfComplete);
                }
                if (this._curloader && this._url)
                {
                    this._curloader.unload(this._url);
                }
                this._args = null;
                this._loader = null;
                this._disposed = true;
            }
            return;
        }// end function

    }
}
